package gosu;

import com.sun.opengl.util.texture.Texture;
import javax.media.opengl.GL;
import javax.media.opengl.glu.GLU;

public class ImageDrawRotOp extends DrawOp {
  private Image _image;
  private ImageDrawOp _drawOp;
  private double _x;
  private double _y;
  private double _angle;
  private double _offsetX;
  private double _offsetY;

  
  public ImageDrawRotOp(Image image, double x, double y, double z, double angle) {
    this(image, x, y, z, angle, 0.5, 0.5);
  }


  public ImageDrawRotOp(Image image, double x, double y, double z, double angle, double centerX, double centerY) {
    _drawOp = new ImageDrawOp(image, x, y, z);
    _angle = angle;
    _x = x;
    _y = y;
    _offsetX = centerX * image.getWidth();
    _offsetY = centerY * image.getHeight();
  }


  public ImageDrawRotOp(Image image, 
                        double x, double y, double z, 
                        double angle, 
                        double centerX, double centerY, 
                        double factorX, double factorY) {
    _drawOp = new ImageDrawOp(image, x, y, z, factorX, factorY);
    _angle = angle;
    _x = x;
    _y = y;
    _offsetX = centerX * image.getWidth() * factorX;
    _offsetY = centerY * image.getHeight() * factorY;
  }


  public ImageDrawRotOp(Image image, 
                        double x, double y, double z, 
                        double angle, 
                        double centerX, double centerY, 
                        double factorX, double factorY, 
                        Color color, int mode) {
    _drawOp = new ImageDrawOp(image, x, y, z, factorX, factorY, color, mode);
    _angle = angle;
    _x = x;
    _y = y;
    _offsetX = centerX * image.getWidth() * factorX;
    _offsetY = centerY * image.getHeight() * factorY;
  }


  public double getZ() { return _drawOp.getZ(); }


  public void execute() {
    GL gl = GLU.getCurrentGL();

    gl.glMatrixMode(GL.GL_MODELVIEW);

    gl.glPushMatrix();
    //gl.glTranslated(_x + _offsetX, _y + _offsetY, 0);
    gl.glTranslated(_x, _y, 0);
    gl.glRotated(_angle, 0, 0, 1);
    gl.glTranslated(-(_x + _offsetX), -(_y + _offsetY), 0);
    _drawOp.execute();
    gl.glPopMatrix();
  }
}
